package com.donn.securitycontrolplatform.userrole.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.donn.securitycontrolplatform.common.Result;
import com.donn.securitycontrolplatform.db1.mapper.TUserRoleMapper;
import com.donn.securitycontrolplatform.userrole.entity.TUserRole;
import com.donn.securitycontrolplatform.userrole.service.ITUserRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户信息表 服务实现类
 * </p>
 *
 * @author zhenglixiang
 * @since 2022-06-10
 */
@Service
@Slf4j
public class ITUserRoleServiceImpl extends ServiceImpl<TUserRoleMapper, TUserRole> implements ITUserRoleService {
    @Override
    public Result insertUserRole(TUserRole userRole) {
        try {
            if (save(userRole)) {
                return Result.success("");
            }
        } catch (Exception e) {
            log.error("insert error :", e);
        }
        return Result.init(500, "fail", "");
    }
    @Override
    public Result updateUserRole(TUserRole userRole) {
        try {
            if (updateById(userRole)) {
                return Result.success("");
            }
        } catch (Exception e) {
            log.error("update error :", e);
        }
        return Result.init(500, "fail", "");
    }
    @Override
    public Result deleteUserRole(Long userId) {
        try {
            if (removeById(userId)) {
                return Result.success("");
            }
        } catch (Exception e) {
            log.error("delete error :", e);
        }
        return Result.init(500, "fail", "");
    }

    @Override
    public Result getUserRoleById(Long userId) {
        try {
            QueryWrapper<TUserRole> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(TUserRole::getUserId, userId);
            return Result.success(list(queryWrapper));
        } catch (Exception e) {
            log.error("delete error :", e);
        }
        return Result.init(500, "fail", "");
    }
}
